package com.moli.iov.admin.service.impl;

import com.moli.iov.admin.service.VehicleFenceService;
import com.moli.iov.base.model.dto.req.VehicleFenceReqDto;
import com.moli.iov.base.model.dto.res.VehicleFenceResDto;
import com.moli.iov.base.remote.IVehicleFenceRemoteService;
import com.moli.iov.enums.UserTypeEnum;
import com.moli.iov.model.dto.req.PageExtend;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.sys.model.po.Company;
import com.moli.iov.sys.remote.ICompanyRemoteService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 *
 * @author whl
 */
@Service
public class VehicleFenceServiceImpl implements VehicleFenceService {

  @Reference(group = "${service.group}", check = false)
  private IVehicleFenceRemoteService iVehicleFenceRemoteService;
  @Reference(group = "${service.group}", check = false)
  private ICompanyRemoteService iCompanyRemoteService;


  @Override
  public RestResponse saveVehicleFence(VehicleFenceReqDto dto) {
    //校验企业
    if (dto.getSysUserType().intValue()== UserTypeEnum.COMPANY.getFlag()){
      dto.setCompanyId(dto.getSysCompanyId());
    }
    Company company = iCompanyRemoteService.companyValid(dto.getCompanyId());
    dto.setCompanyName(company.getCompanyName());
    return iVehicleFenceRemoteService.saveVehicleFence(dto);
  }

  @Override
  public RestResponse updateVehicleFence(VehicleFenceReqDto dto) {
    if (dto.getSysUserType().intValue()== UserTypeEnum.COMPANY.getFlag()){
      dto.setCompanyId(dto.getSysCompanyId());
    }
    //校验企业
    Company company = iCompanyRemoteService.companyValid(dto.getCompanyId());
    dto.setCompanyName(company.getCompanyName());
    return iVehicleFenceRemoteService.updateVehicleFence(dto);
  }

  @Override
  public RestResponse deleteVehicleFence(VehicleFenceReqDto dto) {
    return iVehicleFenceRemoteService.deleteVehicleFence(dto);
  }

  @Override
  public RestResponse<PageExtend<VehicleFenceResDto>>  listVehicleFence(VehicleFenceReqDto dto) {
    return iVehicleFenceRemoteService.listVehicleFence(dto);
  }

  @Override
  public RestResponse redrawVehicleFence(VehicleFenceReqDto dto) {
    return iVehicleFenceRemoteService.redrawVehicleFence(dto);
  }
}
